package cn.com.surker.sale.entity;

import cn.com.surker.util.DateUtil;
import cn.com.surker.util.StringUtils;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Date;

/**
 * <p>
 * 销售项目收款表
 * </p>
 *
 * @author admin
 * @since 2024-06-18
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class SaleContractPayment implements Serializable {

	private static final long serialVersionUID = 1L;

	public SaleContractPayment() {
	}

	public SaleContractPayment(Long orgId, String orgName, String payOrigin, Integer type, Double money,
							   String payType, String cashier, Date payTime, String creater, Date createTime) {
		this.orgId = orgId;
		this.orgName = orgName;
		this.payOrigin = payOrigin;
		this.type = type;
		this.money = money;
		this.payType = payType;
		this.cashier = cashier;
		this.payTime = payTime;
		this.creater = creater;
		this.createTime = createTime;
	}

	@TableId(value = "id", type = IdType.AUTO)
	private Long id;

	/**
	 * 公司ID
	 */
	@NotNull(message = "请选择回款公司")
	private Long orgId;

	/**
	 * 公司
	 */
	private String orgName;

	/**
	 * 项目ID
	 */
	@NotNull(message = "请选择合同信息")
	private Long conId;

	/**
	 * 项目名称
	 */
	private String conName;

	/**
	 * 客户名称
	 */
	private String clientName;

	/**
	 * 支付单位
	 */
	@NotNull(message = "请输入支付单位信息")
	private String payOrigin;

	/**
	 * 类型(后台枚举PaymentTypeEnum)
	 */
	@NotNull(message = "请选择支付类型")
	private Integer type;

	/**
	 * 回款金额
	 */
	@NotNull(message = "请输入回款金额")
	private Double money;

	/**
	 * 是否未销售人员添加,0:不是;1:是;2:销售人员添加且财务已经回款了;
	 */
	private Integer saleAdd;

	/**
	 * 财务显示的金额
	 */
	@TableField(exist = false)
	private String finMoney;

	public String getFinMoney() {
		finMoney = StringUtils.financialDisplay(this.money);
		return finMoney;
	}

	@TableField(exist = false)
	private String bigMoney;

	public String getBigMoney() {
		bigMoney = StringUtils.toMoneyUpperCase(this.money);
		return bigMoney;
	}

	/**
	 * 转账方式
	 */
	private String payType;

	/**
	 * 销售人员
	 */
	private String sale;

	/**
	 * 领用人员
	 */
	private String confirmUser;

	/**
	 * 销售确认时间
	 */
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	private Date saleConfirmDate;

	/**
	 * 出纳人员
	 */
	private String cashier;

	/**
	 * 支付时间
	 */
//	 @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	private Date payTime;

	/**
	 * 状态(0:启用1：禁用)
	 */
	private Integer status;

	/**
	 * 是否已审核
	 */
	private Integer isCheck;

	/**
	 * 是否已打印
	 */
	private Integer isPrint;
	/**
	 * 是否计入已收账款表
	 */
	private Integer isReport;

	private String saleRemark;

	/**
	 * 审核备注，当审核结果为不通过时，必填
	 */
	private String remark;

	/**
	 * 打印备注
	 */
	@TableField(exist = false)
	private String printRemark;

	public String getPrintRemark() {
		Long orgId = this.orgId;
		String r1 = this.remark;
		if (!StringUtils.isNull(orgId)) {
			if ((orgId != null && orgId == 30l) || money < 0) {
				if (!StringUtils.isNull(this.saleRemark))
					return this.saleRemark;
				return "";
			}
		}
		String r2 = "";
		String r3 = "";
		//	销售认领时间
		Date payTime = this.payTime;
		if (StringUtils.isBlank(r1)) {
			r1 = "";
		}
		if (payTime != null) {
			r3 = "回款时间:" + DateUtil.convertString(payTime);
		}
		if (StringUtils.isNotBlank(r1) && StringUtils.isNotBlank(r3)) {
			r2 = ";";
		}
		String res = r1 + r2 + r3;
		return res;
	}

	/**
	 * 创建人
	 */
	private String creater;

	/**
	 * 创建日期
	 */
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	private Date createTime;

	/**
	 * 更新人
	 */
	private String updater;

	/**
	 * 更新日期
	 */
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	@TableField(fill = FieldFill.UPDATE, update = "now()")
	private Date updateTime;

	@TableField(exist = false)
	private String invoiceIds;

}
